package com.yunhe.portal.controller;

import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.model.ResultObject;
import com.yunhe.common.model.mybatis.PageResult;
import com.yunhe.portal.domain.DataBannerInfo;
import com.yunhe.portal.model.BannerInfoQueryCondition;
import com.yunhe.portal.model.DataBannerInfoVo;
import com.yunhe.portal.model.NewsAndNotice;
import com.yunhe.portal.service.DataBannerInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: DataBannerInfoController
 * @Description:
 * @author: GongDaCheng
 * @Date: 9:42 2021/10/22
 */
@Api(value = "DataBannerInfo", description = "data_banner_info维护", tags = {"门户管理Banner维护"})
@RestController
@RequestMapping(value = "/dataBannerInfo")
public class DataBannerInfoController {

    @Autowired
    private DataBannerInfoService dataBannerInfoService;

    @ApiOperation("新增banner")
    @PostMapping("/createDataBannerInfo")
    public ResponseEntity<ResultObject> createDataBannerInfo(@RequestBody DataBannerInfo dataBannerInfo) throws ArgumentErrorException {
        dataBannerInfoService.createDataBannerInfo(dataBannerInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据id删除banner")
    @DeleteMapping("/deleteDataBannerInfo")
    public ResponseEntity<ResultObject> deleteDataBannerInfo(@RequestParam(value = "id",required = true) Long id){
        dataBannerInfoService.deleteDataBannerInfo(id);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("更新banner")
    @PostMapping("/updateDataBannerInfo")
    public ResponseEntity<ResultObject> updateDataBannerInfo(@RequestBody DataBannerInfo dataBannerInfo){
        dataBannerInfoService.updateDataBannerInfo(dataBannerInfo);
        return new ResponseEntity<>(new ResultObject<>(), HttpStatus.OK);
    }

    @ApiOperation("根据id查询banner")
    @GetMapping("/findDataBannerInfoById")
    public ResponseEntity<ResultObject<DataBannerInfo>> findDataBannerInfoById(@RequestParam(value = "id",required = true) Long id){
        return new ResponseEntity<>(new ResultObject(dataBannerInfoService.findDataBannerInfoById(id)),HttpStatus.OK);
    }

    @ApiOperation("置顶banner")
    @PutMapping("/setTop")
    public ResponseEntity<ResultObject> setTop(@RequestParam(value = "id",required = true) Long id) throws ArgumentErrorException {
        dataBannerInfoService.setTop(id);
        return new ResponseEntity<>(new ResultObject(),HttpStatus.OK);
    }

    @ApiOperation("Web根据条件筛选banner")
    @PostMapping("/getBannerByConditionWeb")
    public ResponseEntity<ResultObject<List<DataBannerInfoVo>>> getBannerByConditionWeb(@RequestBody BannerInfoQueryCondition bannerInfoQueryCondition) throws ArgumentErrorException {
        PageResult result = dataBannerInfoService.getBannerByConditionWeb(bannerInfoQueryCondition);
        return new ResponseEntity(new ResultObject<>(result), HttpStatus.OK);
    }

    @ApiOperation("新增Banner获取新闻和公告url")
    @GetMapping("/getNewsAndNoticeByKeyword")
    public ResponseEntity<ResultObject<List<NewsAndNotice>>> getNewsAndNoticeByKeyword (@RequestParam(value = "keyword", required = false) String keyword,
                                                                                        @RequestParam(value = "type", required = true) String type,
                                                                                        @RequestParam(value = "noticeType", required = true) String noticeType){
        List<NewsAndNotice> newsAndNotice = dataBannerInfoService.getNewsAndNoticeByKeyword(keyword, type,noticeType);
        return new ResponseEntity(new ResultObject<>(newsAndNotice), HttpStatus.OK);
    }
}
